package com.shiguiwu.langchain.controller;

import com.shiguiwu.langchain.service.ChatDeclareService;
import com.shiguiwu.langchain.service.ChatService;
import dev.langchain4j.model.openai.OpenAiChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * @description: 聊天controller
 * @author: stone
 * @date: Created by 2025/6/18 19:45
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.langchain.controller
 */
@RestController
public class ChatController {


    @Autowired
    private OpenAiChatModel model;


    /**
     * 使用模型交互
     * @param message
     * @return
     */
    @RequestMapping("/chat")
    public String chat(String message){
        String result = model.chat(message);
        return result;
    }



    /**
     * ai-service 编程式
     * @param message
     * @return
     */

    @Autowired
    private ChatService chatService;


    @RequestMapping("/chatInterface")
    public String chatInterface(String message){
        String result = chatService.chat(message);
        return result;
    }

    /**
     * 声明式
     */
    @Autowired
    private ChatDeclareService  chatDeclareService;


    @RequestMapping("/chatDeclare")
    public String chatDeclare(String message){
        String result = chatDeclareService.chat(message);
        return result;
    }


    @RequestMapping(value = "/chatStream",produces = "text/html;charset=utf-8")
    public Flux<String> chatStream(String message){
        Flux<String> result = chatDeclareService.chatStream(message);
        return result;
    }

    @RequestMapping(value = "/chatMemory", produces = "text/html;charset=utf-8")
    public Flux<String> chatMemory(Integer memoryId, String message) {
        Flux<String> result = chatDeclareService.chatMemory(memoryId, message);
        return result;
    }

    @RequestMapping(value = "/chatRedisMemory", produces = "text/html;charset=utf-8")
    public Flux<String> chatRedisMemory(Integer memoryId, String message) {
        Flux<String> result = chatDeclareService.chatRedisMemory(memoryId, message);
        return result;
    }


    @RequestMapping(value = "/chatEmbedding", produces = "text/html;charset=utf-8")
    public Flux<String> chatEmbedding(Integer memoryId, String message) {
        Flux<String> result = chatDeclareService.chatEmbedding(memoryId, message);
        return result;
    }

    @RequestMapping(value = "/chatEmbedStore", produces = "text/html;charset=utf-8")
    public Flux<String> chatEmbedStore(Integer memoryId, String message) {
        Flux<String> result = chatDeclareService.chatEmbedding(memoryId, message);
        return result;
    }


}
